Namespaces
Variants

std::literals::complex_literals:: operator""i, operator""if, operator""il

From cppreference.net
Défini dans l'en-tête <complex>
constexpr complex < double > operator "" i ( long double arg ) ;
constexpr complex < double > operator "" i ( unsigned long long arg ) ;
(1) (depuis C++14)
constexpr complex < float > operator "" if ( long double arg ) ;
constexpr complex < float > operator "" if ( unsigned long long arg ) ;
(2) (depuis C++14)
constexpr complex < long double > operator "" il ( long double arg ) ;
constexpr complex < long double > operator "" il ( unsigned long long arg ) ;
(3) (depuis C++14)

Forme un littéral std::complex représentant un nombre imaginaire.

1) Forme un littéral std:: complex < double > avec la partie réelle nulle et la partie imaginaire arg .
2) Forme un littéral std:: complex < float > avec la partie réelle nulle et la partie imaginaire arg .
3) Forme un littéral std:: complex < long double > avec la partie réelle nulle et la partie imaginaire arg .

Table des matières

Paramètres

arg - la valeur du nombre imaginaire

Valeur de retour

Le littéral std::complex avec la partie réelle nulle et la partie imaginaire arg .

Notes

Ces opérateurs sont déclarés dans l'espace de noms std :: literals :: complex_literals , où à la fois literals et complex_literals sont des espaces de noms inline. L'accès à ces opérateurs peut être obtenu avec l'une des méthodes suivantes :

  • using namespace std :: literals ,
  • using namespace std :: complex_literals , ou
  • using namespace std :: literals :: complex_literals .

Bien que if soit un mot-clé en C++, il s'agit d'un suffixe utilisateur de l' opérateur littéral de la forme operator "" if et dans les expressions littérales telles que 1if ou 1.0if car il n'est pas séparé par un espace blanc et ne constitue pas un jeton autonome.

Macro de test de fonctionnalité Valeur Std Fonctionnalité
__cpp_lib_complex_udls 201309L (C++14) Littéraux définis par l'utilisateur pour std::complex

Implémentation possible

operator""i
constexpr std::complex<double> operator""i(unsigned long long d)
{
    return std::complex<double> {0.0, static_cast<double>(d)};
}
constexpr std::complex<double> operator""i(long double d)
{
    return std::complex<double> {0.0, static_cast<double>(d)};
}
operator""if
constexpr std::complex<float> operator""if(unsigned long long d)
{
    return std::complex<float> {0.0f, static_cast<float>(d)};
}
constexpr std::complex<float> operator""if(long double d)
{
    return std::complex<float> {0.0f, static_cast<float>(d)};
}
operator""il
constexpr std::complex<long double> operator""il(unsigned long long d)
{
    return std::complex<long double> {0.0L, static_cast<long double>(d)};
}
constexpr std::complex<long double> operator""il(long double d)
{
    return std::complex<long double> {0.0L, d};
}

Exemple

#include <complex>
#include <iostream>
int main()
{
    using namespace std::complex_literals;
    std::complex<double> c = 1.0 + 1i;
    std::cout << "abs" << c << " = " << std::abs(c) << '\n';
    std::complex<float> z = 3.0f + 4.0if;
    std::cout << "abs" << z << " = " << std::abs(z) << '\n';
}

Sortie :

abs(1,1) = 1.41421
abs(3,4) = 5

Voir aussi

construit un nombre complexe
(fonction membre publique)
assigne le contenu
(fonction membre publique)